package com.miguo.http;

import com.miguo.framework.authorize.Sign;
import com.miguo.framework.request.JsonData;
import com.miguo.framework.request.RequestData;
import com.miguo.framework.request.RequestJsonHandler;
import com.miguo.framework.request.SimpleRequest;

import java.util.Map;


public class HttpClient {
	
	/* POST请求 */
	/* 不带参数 */
	public static void post(String url, RequestJsonHandler jsonHandler) {
		Map<String, String> data = Sign.Encrypt();
		send(url, data, jsonHandler);
	}
	
	public static void post(String url, Map<String, String> params,RequestJsonHandler jsonHandler) {
		Map<String, String> data = Sign.Encrypt(params);
		send(url, data, jsonHandler);
	}
	
	public static void postEncryptData(String url, Map<String, String> params,RequestJsonHandler jsonHandler) {
		Map<String, String> data = Sign.EncryptData(params);
		send(url,data,jsonHandler);
	}

	private static void send(String url,Map<String, String> params,RequestJsonHandler jsonHandler){
		SimpleRequest<JsonData> request = new SimpleRequest<JsonData>(
				jsonHandler);
		RequestData requestData = request.getRequestData();
		requestData.setRequestUrl(url);
		requestData.addPostData(params);
		requestData.addHeader("X-MeGuo-Platform", "Android");
		requestData.addHeader("X-MeGuo-Api-Version", "1");
		request.send();
	}
	

}